/*
  (C) 2007 - Boston University
  Contact: Michael Ocean 

	Parts of this file were adapted from a CS511 submission

  This work is a part of the larger snBench project.  Information
  can be found at: http://csr.bu.edu/snbench 

  This program is free software; you can redistribute it and/or
  modify it under the terms of Version 2 of the GNU General Public 
  License.
  
  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  General Public License for more details.
  
  You should have received a copy of the GNU Library General Public
  License along with this library; if not, write to the Free
  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
package stepide;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ButtonGroup;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JToggleButton;
import javax.swing.JToolBar;


public class ToolBarFactory extends JToolBar{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private MenuFactoryListener responder;

	private JToggleButton btnArrowMode = new JToggleButton("CONNECTOR");
	private JToggleButton btnNodeMode = new JToggleButton("NODES");

	/****************************************/
	/**
	 * Creates the frame tool bar.
	 * 
	 * @return the frame tool bar
	 */
	
	private ToolBarFactory(){
		super();
	}
	
	private void SetMode(){
		responder.doActionSetArrowMode(btnArrowMode.isSelected());
	}
	
	public ToolBarFactory(MenuFactoryListener mfl){
		super();
		responder = mfl;	

		this.setRollover(true);
		this.setFloatable(false);
		
		ButtonGroup bg = new ButtonGroup();
		btnArrowMode.setEnabled(true);
		btnNodeMode.setEnabled(true);
		
		bg.add(btnArrowMode);
		bg.add(btnNodeMode);
		btnArrowMode.setToolTipText("Select this mode to connect nodes");
		btnNodeMode.setToolTipText("Select this mode to create nodes");
		
		btnArrowMode.setSelected(false);
		btnNodeMode.setSelected(true);
		
		btnArrowMode.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e) {
				SetMode();		
			}
		});
		btnNodeMode.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e) {
				SetMode();		
			}
		});

		
		JButton newFile = new JButton(new ImageIcon("stepide/icons/New16.gif"));
		newFile.setToolTipText("Create a new STEP Graph");
		newFile.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				responder.doActionFileNew(e);
			}
		});

		JButton open = new JButton(new ImageIcon("stepide/icons/Open16.gif"));
		open.setToolTipText("Open an existing STEP XML file");
		open.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				responder.doActionFileOpen(e);
			}
		});

		JButton save = new JButton(new ImageIcon("stepide/icons/Save16.gif"));
		save.setToolTipText("Save the current graph");
		save.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				responder.doActionFileSave(e);
			}
		});

		JButton print = new JButton(new ImageIcon("stepide/icons/Print16.gif"));
		print.setToolTipText("Sends the current STEP graph to the printer");
		print.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				responder.doActionFilePrint(e);
			}
		});

		JButton xml = new JButton(new ImageIcon("stepide/icons/XmlIcon16.gif"));
		xml.setToolTipText("Refresh the XML behind the current STEP Graph");
		xml.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				responder.doActionViewXml(e);
			}
		});

		JButton run = new JButton(new ImageIcon("stepide/icons/Run16.gif"));
		run.setToolTipText("Bind STEP Graph to SXE");
		run.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				responder.doActionBindToSxe(e);
			}
		});
		
		JButton remove = new JButton(new ImageIcon("stepide/icons/Remove16.gif"));
		remove.setToolTipText("Removes the selected node/edge from the STEP graph");
		remove.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				responder.doActionEditRemoveSelection(e);
			}
		});

		JButton zoomIn = new JButton(new ImageIcon("stepide/icons/ZoomIn16.png"));
		zoomIn.setToolTipText("Increase the zoom level to the next preset value");
		zoomIn.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				responder.doActionViewZoomIn(e);
			}
		});

		JButton zoomOut = new JButton(new ImageIcon("stepide/icons/ZoomOut16.png"));
		zoomOut.setToolTipText("Decrease the zoom level to the next preset value");
		zoomOut.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				responder.doActionViewZoomOut(e);
			}
		});
			
		JButton undo = new JButton(new ImageIcon("stepide/icons/Undo16.gif"));
		undo.setToolTipText("Undo the previous action");
		undo.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				responder.doActionEditUndo(e);
			}
		});
		
		JButton redo = new JButton(new ImageIcon("stepide/icons/Redo16.gif"));
		redo.setToolTipText("Redo the most recently undone action");
		redo.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				responder.doActionEditRedo(e);
			}
		});
		
		this.addSeparator();
		this.add(new JLabel("mode:"));
		this.add(btnArrowMode);
		this.add(btnNodeMode);
		this.addSeparator();
		this.add(newFile);
		this.add(open);
		this.add(save);
		this.add(print);
		this.add(new JToolBar.Separator());
		this.add(undo);
		this.add(redo);
		this.add(new JToolBar.Separator());
		this.add(remove);
		this.add(new JToolBar.Separator());
		this.add(xml);
		this.add(run);
		this.add(new JToolBar.Separator());
		this.add(zoomIn);
		this.add(zoomOut);
				
		SetMode();
	}
}
